<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Class类</title>
</head>
<body>
<script type="text/javascript">
    //ES5中创建一个类
    function Person(name,age){
        this.name = name;
        this.age = age;
    }
    Person.prototype.sayName = function () {
        return this.name;
    }
    let person = new Person('tom',19);
    console.log(person);
    //ES6中使用class关键字
    class Animal{
        constructor(name,age) {
            this.name = name;
            this.age = age;
        }
        sayName(){
            return this.name;
        }
    }
    let animal = new Animal('jerry',2);
    console.log(animal);
    console.log(animal.sayName())
    //class类的继承
    class Dog extends Animal{
        constructor(name,age,color) {
            super(name,age);
            this.color = color;
        }
        syaName(){
            console.log('I am a dog');
        }
    }
    let dog = new Dog('big yellow',2,'yellow');
    console.log(dog);
    dog.syaName();


</script>
</body>
</html>